package com.itheima.Day11;

public class MAY01 implements Runnable {
    private int tickets = 100;
    private Object ob = new Object();

//    public MAY01() {
//    }
//
//    public MAY01(int tickets, Object ob) {
//        this.tickets = tickets;
//        this.ob = ob;
//    }

    @Override
    public void run() {
        while (true) {
            synchronized (ob) {
                if (tickets <= 0)   {
                    break;
                }else {

                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                    System.out.println(Thread.currentThread().getName() + "正在出售第" + tickets + "张票");
                }

            }
        }

    }
}
